import { createRouter, createMemoryHistory, createWebHashHistory, createWebHistory } from "vue-router";


import Login from "../views/login.vue"
import Index from "../views/Index.vue"
import all from "../views/all.vue"
import hsz from "../views/hsz.vue"
import wdfx from "../views/wdfx.vue"
import sz from "../views/sz.vue"
import watchshare from "../views/watchshare.vue"
import webshare from "../views/webshare.vue"
import Cookie from "@/utils/Cookie";
const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: "/",
            name: "login",
            component: Login
        },
        {
            path: "/index",
            name: "index",
            component: Index,
            redirect:"/main",
            children: [
                {
                    path: "/main",
                    name: "all",
                    component: all
                },
                {
                    path: "/hsz",
                    name: "hsz",
                    component: hsz
                },
                                {
                    path: "/wdfx",
                    name: "wdfx",
                    component: wdfx
                },
                              {
                    path: "/sz",
                    name: "sz",
                    component: sz
                },
                
                
            ]
        },
        {
            path:"/watchshare",
            name:"watchshare",
            component:watchshare
        },
                {
            path:"/webshare",
            name:"webshare",
            component:webshare
        }
        


    ]

})
router.beforeEach((to, from, next) => {
    console.log(to, from)
    const userinfo = Cookie.getcookie("userInfo");
    console.log(userinfo)

    if (!userinfo && to.path !== '/') {
        console.log("123")
        router.push({
            path: "/",
            query: {
                url: to.fullPath
            }
        })
    }
    next();

});

export default router;